var GameData = require('../../module/GameData')();
cc.Class({
    extends: cc.Component,

    properties: {

        goods1_bgsp: {
            default: null,
            type: cc.Sprite,
            tooltip: 'good1的bgsp',
        },
        goods1_title: {
            default: null,
            type: cc.Label,
            tooltip: 'good1的title',
        },
        goods1_goods_icon: {
            default: null,
            type: cc.Sprite,
            tooltip: 'good1的sp',
        },
        goods1_limit_num: {
            default: null,
            type: cc.Label,
            tooltip: 'good1的今日购买次数',
        },
        goods1_limit_Allnum: {
            default: null,
            type: cc.Label,
            tooltip: 'good1的今日限购次数',
        },
        goods1_buy_icon: {
            default: null,
            type: cc.Sprite,
            tooltip: 'good1的钻石或者金币icon图标',
        },
        goods1_buy_num: {
            default: null,
            type: cc.Label,
            tooltip: 'good1的价格',
        },

        goods2_bgsp: {
            default: null,
            type: cc.Sprite,
            tooltip: 'good2的bgsp',
        },
        goods2_goods_icon: {
            default: null,
            type: cc.Sprite,
            tooltip: 'good2的sp',
        },
        goods2_goodsNum: {
            default: null,
            type: cc.Label,
            tooltip: 'good2的道具数量',
        },
        goods2_Price_icon: {
            default: null,
            type: cc.Sprite,
            tooltip: 'good2的钻石或者金币icon图标',
        },
        goods2_goodsPrice: {
            default: null,
            type: cc.Label,
            tooltip: 'good2的道具价格',
        },

        shop_All: cc.SpriteAtlas,

    },


    // LIFE-CYCLE CALLBACKS:

    onLoad() {

    },
    init(data) {
        if (this.node.name === "goods1") {
            /*商店货物1*/
            this.initgoods1(data)
        } else {
            /*商店货物2*/
            this.initgoods2(data)
        }

    },
    initgoods1(data) {
        this.goods1_title.string = data.title;
        this.goods1_limit_num.string = data.limit_num;
        this.goods1_limit_Allnum.string = data.limit_Allnum;
        this.goods1_buy_num.string = data.buy_num;

        this.goods1_goods_icon.getComponent(cc.Sprite).spriteFrame = this.shop_All.getSpriteFrame(data.goods_icon);
        this.goods1_buy_icon.getComponent(cc.Sprite).spriteFrame = this.shop_All.getSpriteFrame(data.buy_icon);
        this.data = data;

    },
    initgoods2(data) {
        this.goods2_goods_icon.getComponent(cc.Sprite).spriteFrame = this.shop_All.getSpriteFrame(data.goods_icon);
        this.goods2_goodsNum.string = data.goods_Num;
        this.goods2_Price_icon.getComponent(cc.Sprite).spriteFrame = this.shop_All.getSpriteFrame(data.Price_icon);
        this.goods2_goodsPrice.string = data.goods_price;
        this.data = data;
    },
    selectbtn() {
        let _data = {
            goods_sp: "",
            btn_icon: "",
            goods_dsc: "",
            btn_num: "",
        };
        if (this.node.name === "goods1") {
            _data = {
                goods_sp: this.data.goods_icon,
                btn_icon: this.data.buy_icon,
                goods_dsc: this.data.title,
                btn_num: this.data.buy_num,
            };
        } else {
            _data = {
                goods_sp: this.data.goods_icon,
                btn_icon: this.data.Price_icon,
                goods_dsc: this.data.goods_Num,
                btn_num: this.data.goods_price,
            };
        }
        GameData.shop.showBuy(_data);
    },

    start() {

    },

    // update (dt) {},
});
